<template>
	<view>

		<!-- 首页图片 -->
		<!-- 把当前点击的图片的索引，传递到 preview() 处理函数中 -->
		<view class="image-box">
			<image :src="goods.indexImg" @click="preview(i)" class=".product-index-image"></image>
		</view>
		<!-- 商品信息区域 -->
		<view class="goods-info-box">
			<!-- 商品价格 -->
			<view class="price">￥{{goods.price}}</view>
			<!-- 信息主体区域 -->
			<view class="goods-info-body">
				<!-- 商品名称 -->
				<view class="goods-name">{{goods.name}}</view>
			</view>
		</view>
		<!-- 商品详情 -->
		<view class="goods-content">
			<view class="goods-detail" style="padding-bottom: 15rpx;">
				{{goods.detail}}
			</view>
			<view class="image-box" v-for="(item,i) in goodsPic" :key="i">
				<img :src="item.url" alt="" class="goods-image">
			</view>
		</view>
		<view class="sender-box">
			<view class="sender">
				<image :src="goods.userImg" mode="" class="sender-img"></image>
				<view class="sender-name">
					{{goods.senderName}}
				</view>
			</view>
			<view class="sender-button">
				<button size="mini">联系我</button>
				<button size="mini" style="background-color: #ffeb37; margin-left: 5%;" >下单</button>
			</view>
		</view>

		

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 商品详情对象
				goods: {},
				goodsPic:[],
				// 左侧按钮组的配置对象
				options: [{
					icon: 'shop',
					text: '店铺'
				}, {
					icon: 'cart',
					text: '购物车',
					info: 0
				}],
				// 右侧按钮组的配置对象
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			};
		},
		onLoad(options) {
			// 获取商品 Id
			const goods_id = options.goods_id;
			this.getGoodsDetail(goods_id);
			this.getPic(goods_id);
		},
		methods: {
			// 定义请求商品详情数据的方法
			async getGoodsDetail(goods_id) {
				const {
					data: res
				} = await
				uni.$http.get('/bbm/goods/info/' + goods_id)
				console.log(res);
				this.goods = res.goods;
			},
			async getPic(goods_id){
				const {
					data: res
				} = await
				uni.$http.get('/bbm/goodspic/getImgByGoodsId/' + goods_id)
				this.goodsPic=res.goodsPic
			},
			// 实现轮播图的预览效果
			preview(i) {
				// 调用 uni.previewImage() 方法预览图片
				uni.previewImage({
					// 预览时，默认显示图片的索引
					current: i,
					urls: [this.goods.indexImg]
				})
			},
			
		
		}
	}
</script>

<style lang="scss">
	// 轮播图
	swiper {
		height: 750rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	// 商品信息区域的样式
	.goods-info-box {
		padding: 10px;
		padding-right: 0;
		border-bottom:1px solid #efefef;

		.price {
			color: #c00000;
			font-size: 18px;
			margin: 10px 0;
		}

		.goods-info-body {
			display: flex;
			justify-content: space-between;

			.goods-name {
				font-size: 13px;
				padding-right: 10px;
			}

			// 收藏区域
			.favi {
				width: 120px;
				font-size: 12px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				border-left: 1px solid #efefef;
				color: gray;
			}
		}

		// 运费
		.yf {
			margin: 10px 0;
			font-size: 12px;
			color: gray;
		}
	}

	.goods-detail-container {
		// 给页面外层的容器，添加 50px 的内padding，
		// 防止页面内容被底部的商品导航组件遮盖
		padding-bottom: 50px;
	}

	.goods_nav {
		// 为商品导航组件添加固定定位
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
	}

	.image-box {
		width: 100%;
		height: 0;
		padding-top: 100%;
		position: relative;

		.product-index-image {
			border-radius: 2%;
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}
	}
	
	.sender-box{
		background-color: whitesmoke;
		border-top: 1px solid #efefef;
		width: 100%;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		justify-items: center;
		align-items: center;
		.sender{
			display: flex;
			justify-items: center;
			align-items: center;
			width: 60%;
			.sender-img{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin-top: 10rpx;
				margin-left: 10rpx;
			}
			.sender-name{
				margin-left: 30rpx;
				font-size: 40rpx;
				font-weight: bold;
			}
		}
		.sender-button{
			width: 40%;
			display: flex;
		}
	}
	
	.goods-content{
		padding-bottom: 55px;
		margin-left: 2%;
		margin-right: 2%;
		padding-top: 20rpx;
		width: 96%;
		.image-box {
			width: 100%;
			height: 0;
			margin-top: 20rpx;
			padding-top: 100%;
			position: relative;
			.goods-image {
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
			}
		}
		.goods-pic{
			max-width: 100%;
			
			object-fit: contain;
		}
	}
</style>